/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-05-15
 * Time:22:13
 */
public class OutClass {
    public int data1=1;
    public int data4=99;
    public static int data2=2;
    private int data3=3;

    public void print(){
        /*重名字段名：data4
        外部类data4=99;
        实例内部类data4=44;*/
        OutClass.InnerClass2 innerClass2=new OutClass.InnerClass2();
        System.out.println(innerClass2.data4);
        System.out.println(innerClass2.data8);
        System.out.println(this.data4);
    }
    //实例内部类
    class InnerClass1{
        //重名成员变量
        public int data4=11;
        private int data5=5;
        public static final int DATA=6;

        public void print(){
            //访问内部类的成员
            System.out.println("内部类："+this.data4);
            System.out.println("外部类："+OutClass.this.data4);
            System.out.println(this.data5);
            System.out.println(InnerClass1.DATA);
            //访问外部类的对象
            System.out.println(OutClass.this.data1);
            System.out.println(OutClass.data2);
            System.out.println(OutClass.this.data3);
        }
    }

    //静态内部类
    static class InnerClass2{
        public int data7=7;
        public int data4=44;
        private int data8=9;
        public static final int DATA=9;

        public void print(){
            OutClass outClass=new OutClass();
            //访问外部类字段
            System.out.println(outClass.data1);
            System.out.println(outClass.data3);
            //访问静态内部类字段
            System.out.println(this.data7);
        }
    }
}
